# -*- coding: utf-8 -*-

from wmi import WMI

class ModifyDns:
    def __init__(self, type):
        self.type = type

    def developModel(self):
        wmiService = WMI()
        colNicConfigs = wmiService.Win32_NetworkAdapterConfiguration(IPEnabled = True)
        if len(colNicConfigs) < 1:
            print("没有找到可用的网络适配器")
            exit()

        objNicConfig = colNicConfigs[0]
        arrDNSServers = []
        msg = ""
        if self.type == 0:
            arrDNSServers = ['172.16.101.11']
            msg = "SIT环境DNS修改成功"
        elif self.type == 1:
            arrDNSServers = ['172.16.110.11']
            msg = "UAT环境DNS修改成功"
        elif self.type == 2:
            arrDNSServers = ['172.16.100.243']
            #172.16.100.243
            msg = "STAGE环境DNS修改成功"
        elif self.type == 3:
            returnValue = objNicConfig.SetDNSServerSearchOrder()
            retrunValue = objNicConfig.EnableDHCP()
            print ('自动获取dns')
            exit()

        returnValue = objNicConfig.SetDNSServerSearchOrder(DNSServerSearchOrder = arrDNSServers)

        if returnValue[0] == 0:
            print (msg)
        elif returnValue[0] == 1:
            print (msg)
            print ("修改DNS失败")
if __name__ == '__main__':
    test = ModifyDns(0)
    test.developModel()